﻿using System.Text.RegularExpressions;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.Types;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using Lumina.Excel.Sheets;

namespace Dalamud_UserUpdate
{
    internal class Utils
    {
        public static string GlobToRegex(string glob)
        {
            return Regex.Escape(glob).Replace("\\?", ".").Replace("\\*", ".*");
        }

        public static string GetDutyNameForTerritory(TerritoryType territory)
        {
            string territoryName = territory.ContentFinderCondition.Value.Name.ToString();
            if (string.IsNullOrEmpty(territoryName)) territoryName = territory.PlaceName.Value.Name.ToString();
            if (string.IsNullOrEmpty(territoryName)) return "Unknown";

            // Capitalization correction
            territoryName = territoryName.Replace("- the", "- The");
            territoryName = territoryName.Replace(": the", ": The");
            territoryName = Regex.Replace(territoryName, "^the", "The");
            return territoryName;
        }


        public static unsafe ulong getContentId(IGameObject playerCharacter)
        {
            if (playerCharacter is { } iPlayerCharacter)
            {
                if (iPlayerCharacter.ObjectKind == ObjectKind.Player)
                {
                    var characterAddress = (BattleChara*)iPlayerCharacter.Address;
                    return characterAddress->ContentId;
                }
               
            }
            return 0;
        }
    }
}